//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Text;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

using CommunityServer.Components;

namespace CommunityServer.Discussions.Controls 
{

    public class ForumRolloverImageButton : LinkButton, INamingContainer 
    {
		
        HtmlImage image;

        protected override void CreateChildControls() 
        {
            Controls.Clear();

            image = new HtmlImage();

            switch (ButtonType) 
            {
                case CSButtonType.PostMessage:
                    ImageUrl = Globals.GetSkinPath() + "/images/post_toolbar_post.gif";
					Text = "Post";
                    break;

                case CSButtonType.PreviewMessage:
					ImageUrl = Globals.GetSkinPath() + "/images/post_toolbar_preview.gif";
					Text = "Preview Post";
                    break;

				case CSButtonType.AllowReply:

					if (ButtonOn)
					{
						ImageUrl = Globals.GetSkinPath() + "/images/post_toolbar_replies_on.gif";
						CssClass = "";
					}
					else
					{
						ImageUrl = Globals.GetSkinPath() + "/images/post_toolbar_replies_off.gif";
						CssClass = "greyPostToolbarButton";
					}
					Text = "Deny Replies";
					break;
					
            }

            // Add scripts for highlighting the buttons when clicked and sets CSS on the images
			// This must be done to the image directly because FireFox won't render it properly to the anchor
            //
			if(!Page.IsClientScriptBlockRegistered("PostToolbarButtonOnMouseDown"))
			{
				StringBuilder sb = new StringBuilder("<SCRIPT language='javascript' for='PostToolbarButton' event='onmousedown'>");
				sb.Append("this.className='PostToolbarButtonDown';");
				sb.Append("return true;");
				sb.Append("</script>");
				Page.RegisterClientScriptBlock("PostToolbarButtonOnMouseDown", sb.ToString());
			}
			if(!Page.IsClientScriptBlockRegistered("PostToolbarButtonOnClick"))
			{
				StringBuilder sb = new StringBuilder("<SCRIPT language='javascript' for='PostToolbarButton' event='onclick'>");
				sb.Append("this.className='PostToolbarButton';");
				sb.Append("return true;");
				sb.Append("</script>");
				Page.RegisterClientScriptBlock("PostToolbarButtonOnClick", sb.ToString());
			}

			// Set properties
            //
            Attributes.Add("name", "ForumToolbarButton");
			if(CssClass == "")
				CssClass = "PostToolbarButton";

            // Set the image url
            //
			image.Border = 0;
			image.Src = this.ImageUrl;
			image.Attributes.Add("class", "ForumToolbarButton");

			// Add the image to the anchor
            //
            Controls.Add(image);
			Controls.Add(new LiteralControl(Text));

			// Add the divider image
			//
			HtmlImage divider = new HtmlImage();
			divider.Src = Globals.GetSkinPath() + "/images/post_toolbar_divider.gif";
			divider.Border = 0;
			divider.Attributes.Add("class", "ForumToolbarButton");
			Controls.Add(divider);
        }

		[
        System.ComponentModel.DefaultValue( CSButtonType.PostMessage ),
        ]
        public virtual CSButtonType ButtonType 
        {
            get 
            {
                Object state = ViewState["ButtonType"];
                if ( state != null ) 
                {
                    return (CSButtonType)state;
                }
                return CSButtonType.PostMessage;
            }
            set 
            {
                ViewState["ButtonType"] = value;
            }
        }

		[
		System.ComponentModel.DefaultValue( false ),
		]
		public virtual bool ButtonOn {
			get {
				Object state = ViewState["ButtonOn"];
				if ( state != null ) {
					return (bool)state;
				}
				return false;
			}
			set {
				ViewState["ButtonOn"] = value;
			}
		}

        [
        System.ComponentModel.DefaultValue( "" ),
        ]
        public virtual String Name 
        {
            get 
            {
                Object state = ViewState["Name"];
                if ( state != null ) 
                {
                    return (String)state;
                }
                return "";
            }
            set 
            {
                ViewState["Name"] = value;
            }
        }


        // ***************************************************
        // ImageUrlOnMouseOver
        //
        /// <summary>
        /// Url to the image used when the mouse is over the button
        /// </summary>
        [
        System.ComponentModel.DefaultValue( "" ),
        ]
        public virtual string ImageUrlOnMouseOver 
        {
            get 
            {
                Object state = ViewState["ImageUrlOnMouseOver"];
                if ( state != null ) 
                {
                    return (string)state;
                }
                return "";
            }
            set 
            {
                ViewState["ImageUrlOnMouseOver"] = value;
            }
        }


        // ***************************************************
        // ImageUrlOnMouseDown
        //
        /// <summary>
        /// Url to the image used when the mouse is down over the button
        /// </summary>
        [
        System.ComponentModel.DefaultValue( "" ),
        ]
        public virtual string ImageUrlOnMouseDown 
        {
            get 
            {
                Object state = ViewState["ImageUrlOnMouseDown"];
                if ( state != null ) 
                {
                    return (string)state;
                }
                return "";
            }
            set 
            {
                ViewState["ImageUrlOnMouseDown"] = value;
            }
        }


        // ***************************************************
        // ImageUrl
        //
        /// <summary>
        /// Url to the image used when image is not active
        /// </summary>
        [
        System.ComponentModel.DefaultValue( "" ),
        ]
        public virtual string ImageUrl 
        {
            get 
            {
                Object state = ViewState["ImageUrl"];
                if ( state != null ) 
                {
                    return (string)state;
                }
                return "";
            }
            set 
            {
                ViewState["ImageUrl"] = value;
            }
        }

		
        // ***************************************************
        // Alt
        //
        /// <summary>
        /// Alt text used for the images
        /// </summary>
        /// 
        public string Alt 
        {
            get 
            {
                this.EnsureChildControls();
                return image.Alt;
            }
            set 
            {
                this.EnsureChildControls();
                image.Alt = value;
            }
        }
    }
}
